﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zzva.Common;
using System.Reflection;



namespace Zzva.DomainObject
{
    public abstract class TDirBase:IComparable 
    {

        protected string mvarObozn;
        protected string mvarNaim;
        private Type mvarTypeObject ;





        public override string ToString()
        {
            try{return this.Obozn;}
            catch (Exception e1) { throw e1; }
            finally { }
        }


































































































        //public static TDirBase  operator =(Complex c1, Complex c2)

 ////           public static bool operator ==(TDirBase pDirBase1,TDirBase pDirBase2)
 ////           {
 ////               bool lResult;
 ////               lResult = pDirBase1.Equals(pDirBase2);
 ////               if (lResult == true) { return true; }
 ////               else { return false; }
 ////           }




 ////           public static bool operator !=(TDirBase pDirBase1, TDirBase pDirBase2)
 ////           {
 ////               bool lResult;
 ////               lResult = pDirBase1.Equals(pDirBase2);
 ////               if (lResult == true) { return false ; }
 ////               else { return true ; }
 ////           }






        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType()) return false;
            TDirBase lDirBase = (TDirBase)obj;
            return (this.Obozn == lDirBase.Obozn);
        }


        public override int GetHashCode()
        {
            return this.Obozn.GetHashCode();
        }




        public int CompareTo(object obj)
        {
            try
            {
                TDirBase lOtherTDirBase = obj as TDirBase;
                if (lOtherTDirBase != null)
                { return this.Obozn.CompareTo(lOtherTDirBase.Obozn); }
                else{throw (new CommonException("Object is not a TDirBase"));}
            }
            catch (Exception e1) { throw e1; }
            finally { }
        }
































































        protected TDirBase()
        {
            mvarTypeObject = this.GetType();
        }



        public virtual  int Id
        {
            get
            {
                try { throw (new CommonException("Свойство не реализовано")); }
                catch (Exception e1) { throw e1; }
                finally { }
            }
        }






        public abstract string Obozn
        {
            get;
            set;
        }



        public abstract string Naim
        {
            get;
            set;
        }









        public object GetAttrib(string pObozn)
        {
            try
            {
                object lAttrib;
                object[] lParametrs = new object[1];
                lParametrs = null;
                lAttrib = mvarTypeObject.InvokeMember(pObozn,
                BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty,
                null, this, lParametrs);

                return lAttrib;
            }
            catch (Exception e) { throw e; }
            finally { }
        }





        public void SetAttrib(string pObozn, object pValue)
        {
            try
            {
                object lAttrib;
                object[] lParametrs = new object[1];
                lParametrs[0] = pValue;


                lAttrib = mvarTypeObject.InvokeMember(pObozn,
                       BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null, this, lParametrs);



            }
            catch (Exception e) { throw e; }
            finally { }
        }








    }
}
